import { HanderMenu } from '../../constraint/index';
import {Login} from '../../api/index';
import {alertMessage} from '../../Hook/index';
const HanderMenu: HanderMenu = {
    searchTitle: '欢迎来到网易云音乐',
    placeholder: '歌名按Enter搜索',
    dropdown: [
        {id:'1',title: '设置'},
        {id:'2',title: '退出'}
    ]

}

export default {
    namespaced: true,
    
    actions: {
        /**
         * 登入
         * @param param0 
         * @param value 
         * @returns 
         */
       async login({commit}: any, value: object) {
            console.log('data');
            const {data} = await Login(value)
            if(data.code === 400){
                // 登入错误
                alertMessage('登录', "登入出错啦, 请检查用户名和密码。", 'error')

                return 400
            } else if (data.code === 502) {
                // 用户密码错误
                alertMessage('登录', "密码出错啦", 'warning')
                return 502
            } else if(data.code === 200){
                // 登录成功
                alertMessage('登录', "用户登录成功")
                localStorage.setItem('Profile', JSON.stringify(data.profile))
                localStorage.setItem('Bindings', JSON.stringify(data.bindings))
                localStorage.setItem('token', JSON.stringify(data.token))

                return 200

            }
        },

        breakLogin(){
            localStorage.removeItem('Profile')
            localStorage.removeItem('Bindings')
            localStorage.removeItem('token')
            alertMessage('注销','账户注销成功')

            return 200
        },
        
    },
    mutations: {

    },
    getters: {
        isAdmin() {

        } // -> getters['account/isAdmin']
    },

    // 模块内容（module assets）
    state: () => ({
        HanderMenu
    }), // 模块内的状态已经是嵌套的了，使用 `namespaced` 属性不会对其产生影响
}

 